<?php

namespace app\data\controller\notarialoffice;

use app\data\model\NotarizedTypeModel;
use app\data\model\NotarialOffice as NotarialOfficeModel;
use think\admin\Controller;
use think\admin\helper\QueryHelper;

/**
 * 委托公证类型管理
 * Class Balance
 * @package app\data\controller\notarialoffice
 */
class NotarizedType extends Controller
{
    /**
     * 委托公证类型列表
     * @auth true
     * @menu true
     */
    public function index()
    {
        $this->cates = NotarialOfficeModel::field('id,name')->select()->toArray();
        NotarizedTypeModel::mQuery()->layTable(function () {
            $this->title = "委托公证类型管理";
        }, function (QueryHelper $query) {
            $notarial_office_id = input('notarial_office_id',0);//公证处id
            if ($notarial_office_id) {
                $query->where('notarial_office_id', $notarial_office_id);
            }
            $query->where(['deleted' => 0]);
            $query->like('name')->dateBetween('create_at');
            // $query->append(['notarial_office_name','type_text']);
            $query->append(['notarial_office_name']);
        });
    }

    /**
     * 添加委托公证类型
     * @auth true
     */
    public function add()
    {
        NotarizedTypeModel::mForm('form');
    }

    /**
     * 编辑委托公证类型
     * @auth true
     */
    public function edit()
    {
        NotarizedTypeModel::mForm('form');
    }

    /**
     * 删除委托公证类型
     * @auth true
     */
    public function remove()
    {
        NotarizedTypeModel::mDelete();
    }

    /**
     * 委托公证类型表单处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _form_filter(&$data)
    {
        if ($this->request->isGet()) {
            $this->cates = NotarialOfficeModel::field('id,name')->select()->toArray();
        } else {
        }
    }
}